package com.luotf.util;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

import com.luotf.model.Comments;
/**
 * 评论的工具类
 * @author liujianjun
 *
 */
public class Comments_util {
	
	/**
	 * 
	 *@作者:
	 *@简介:组装评论的一二级评论的
	 * @param NOassembly
	 * @return
	 */
	public static List<Comments> AssemblyComments(List<Comments> NOassembly){
		
		List<Comments> Level1 = new ArrayList<Comments>();
		List<Comments> Level2 = new ArrayList<Comments>();
		
		for(Comments comment:NOassembly) {
			if(comment.getParentCommId()==null||"".equals(comment.getParentCommId().toString())) {
				Level1.add(comment);
			}else {
				Level2.add(comment);
			}
		}
		//按时间排序
		Collections.sort(Level1);
		
		for(Comments level1:Level1) {
			for(Comments level2:Level2) {
				if(level2.getParentCommId().equals(level1.getId()) ) {
					level1.getChildComment().add(level2);
				}
			}
			//按时间排序
			Collections.sort(level1.getChildComment());
		}
		
		return Level1;
	}
	
}
